package com.mall.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.business.domain.TCashbackRule;
import com.mall.business.service.ITCashbackRuleService;
import com.mall.common.core.page.TableDataInfo;

/**
 * 邀请返现规则Controller
 *
 * @author ruoyi
 * @date 2025-03-31
 */
@RestController
@RequestMapping("/business/rule" )
public class TCashbackRuleController extends BaseController {
    @Autowired
    private ITCashbackRuleService tCashbackRuleService;

/**
 * 查询邀请返现规则列表
 */
//@RequiresPermissions("business:rule:list")
@GetMapping("/list" )
    public TableDataInfo list(TCashbackRule tCashbackRule) {
        startPage();
        List<TCashbackRule> list = tCashbackRuleService.selectTCashbackRuleList(tCashbackRule);
        return getDataTable(list);
    }

    /**
     * 导出邀请返现规则列表
     */
    //@RequiresPermissions("business:rule:export")
    @Log(title = "邀请返现规则" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, TCashbackRule tCashbackRule) {
        List<TCashbackRule> list = tCashbackRuleService.selectTCashbackRuleList(tCashbackRule);
        ExcelUtil<TCashbackRule> util = new ExcelUtil<TCashbackRule>(TCashbackRule. class);
        util.exportExcel(response, list, "邀请返现规则数据" );
    }

    /**
     * 获取邀请返现规则详细信息
     */
    //@RequiresPermissions("business:rule:query")
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) String id) {
        return AjaxResult.success(tCashbackRuleService.getById(id));
    }

    /**
     * 新增邀请返现规则
     */
    //@RequiresPermissions("business:rule:add")
    @Log(title = "邀请返现规则" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCashbackRule tCashbackRule) {
        return toAjax(tCashbackRuleService.save(tCashbackRule));
    }

    /**
     * 修改邀请返现规则
     */
    //@RequiresPermissions("business:rule:edit")
    @Log(title = "邀请返现规则" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCashbackRule tCashbackRule) {
        return toAjax(tCashbackRuleService.updateById(tCashbackRule));
    }

    /**
     * 删除邀请返现规则
     */
    //@RequiresPermissions("business:rule:remove")
    @Log(title = "邀请返现规则" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tCashbackRuleService.removeByIds(Arrays.asList(ids)));
    }
}
